package com.hoas.distributedlock.strategy.redis;

import com.hoas.distributedlock.core.DisributedLock;
import com.hoas.distributedlock.core.DisributedLockStrategy;
import redis.clients.jedis.JedisPool;

public class RedisLockStrategy extends DisributedLockStrategy {

    private JedisPool jedisPool;

    private String prefix;

    public RedisLockStrategy(String name, JedisPool jedisPool, String prefix) {
        super(name);
        this.jedisPool = jedisPool;
        this.prefix = prefix;
    }

    protected DisributedLock create() {

        RedisLock lock = new RedisLock(jedisPool);
        if (prefix != null && prefix.length() == 0) {
            lock.setPrefix( prefix );
        }
        return lock;
        
    }
}
